<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">
            <a-button v-if="allowEdit" type="primary" icon="plus" @click="addPrint">
                {{$ti18('rxList.newBtn',"新建")}}
            </a-button>
            <a-dropdown>
              <a-button style="margin-left: 8px">
                  {{$ti18('rxList.moreBtn','更多')}}
                  <a-icon type="down" />
              </a-button>
              <a-menu slot="overlay">
                <a-menu-item key="1"  @click="editOnePrint"><a-icon type="user" />
                    {{$ti18('rxList.editBtn',"编辑")}}
                </a-menu-item>
                <a-menu-item key="2" @click="delByIds(selectedRowKeys)"><a-icon type="delete" />
                    {{$ti18('rxList.delBtn',"删除")}}
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </div>
          <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow">
            <i class="iconfont iconguolv"></i>
                {{$ti18('rxList.leachBtn','过滤')}}
            </span>
          </span>
        </div>

        <div slot="searchbar" searchdir="right" btnalign="right"  v-if="fitSearch" @search="search" @cancel="resetSearchList" @close="close">
          <a-form :layout="colLayout">
            <a-row :gutter="24">
              <a-col :span="colSpan">
                  <a-form-item :label="i18n('form.templateName','模板名称')">
                      <a-input :placeholder="i18n('form.templateName','模板名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                  </a-form-item>
              </a-col>
              <a-col :span="colSpan">
                <a-form-item :label="i18n('form.alias','别名')">
                  <a-input :placeholder="i18n('form.alias','别名','input')" v-model="queryParam.Q_ALIAS__S_LK"/>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </div>

        <rx-grid
                ref="table"
                :allowRowSelect="true"
                :multiSelect="true"
                :columns="columns"
                :defaultPageSize="10"
                url="/api-form/form/core/formPrintLodop/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="id"
                @selectChange="onSelectChange"
        >
            <span slot="exportApp">
                {{ exportI18n('export.isExport','导出') }}
                <a-tooltip placement="top">
                <template slot="title">
                     <span>{{ exportI18n('export.helpInfo','提示信息') }}</span>
                </template>
                <a-icon type="question-circle" />
                </a-tooltip>
            </span>
            <span slot="isExport" slot-scope="{ text, record }">
                <a-tag :color="text == 1 ? 'green' : 'red'">
                     <span>{{ text == 1 ? exportI18n('export.yes','是') : exportI18n('export.no','否') }}</span>
                </a-tag>
            </span>
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span v-if="allowEdit && editEnable" @click.stop="editPrint(record)">
                {{$ti18('rxList.editBtn',"编辑")}}
            </span>
            <span v-if="allowEdit && removeEnable" @click.stop="delByIds([record.id])">
                {{$ti18('rxList.delBtn',"删除")}}
            </span>
            <span v-if="!allowEdit" @click="selectPrint(record)">
                {{$ti18('rxList.select',"选择")}}
            </span>
            <span @click="setExport(record)">{{record.isExport == 1 ? exportI18n('export.noExport','不导出') : exportI18n('export.exported','导出')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import FormPrintLodopApi from '@/api/form/core/formPrintLodop'
  import FormPrintLodopEdit from './FormPrintLodopEdit'
  import {BaseList, Util} from "@lowcode/jpaas-common-lib";
  export default {
    name: 'FormPrintLodopList',
    mixins: [BaseList],
    props:["layerid","destroy","boId","boName","boDefId","allowEdit"],
    data() {
      return {
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 100,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: this.i18n('form.templateName','模板名称'), dataIndex: 'name', width: 100},
          {title: this.i18n('form.alias','别名'), dataIndex: 'alias', width: 100},
            {
                dataIndex: 'isExport',
                slots: { title: 'exportApp' },
                width: 100,
                scopedSlots: {customRender: 'isExport'}
            },
          {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],
        component:FormPrintLodopEdit,
        comment: this.i18n('list.comment','表单套打模板'),
        widthHeight:['800px','600px'],
      }
    },
    created() {
      this.queryParam['Q_BO_ID__S_EQ'] = this.boDefId;
      this.needFilterAppId();
    },
    methods:{
      i18n(name,text,key){
          return this.$ti18(name,text,"printLodop",key);
      },
        exportI18n(name,text,key){
            return this.$ti18(name,text,"appExport",key);
        },
        // 设置是否导出
        setExport(record) {
            let self_ = this;
            let param = {
                id: record.id,
                isExport: record.isExport == 1 ? 0 : 1
            };
            FormPrintLodopApi.update(param).then(res => {
                if (res.success) {
                    self_.$message.success(res.message);
                    self_.loadData();
                } else {
                    self_.$message.error(self_.exportI18n('export.settingFail','设置失败！'));
                }
            });
        },
      resetSearchList () {
        this.$nextTick(()=>{
          this.queryParam={Q_BO_ID__S_EQ:this.boId};
            let appId=this.curApp.appId;
            if(appId){
                this.queryParam.Q_APP_ID__S_EQ=appId;
            }
          this.$nextTick(()=>{
            this.$refs[this.table].loadData();
          })
        })
      },
      delById(ids){
        return FormPrintLodopApi.del({ ids: ids.join(',') });
      },
      getListByParams(parameter){
        return FormPrintLodopApi.query(parameter)
      },
      selectPrint(record){
        Util.closeWindow(this,"ok",record);
      },
      addPrint(){
        var self_ = this;
        var baseConf = {
          curVm: self_,
          component: this.component,
          title: this.$ti18('rxList.newBtn',"添加") + this.comment,
          max:true,
          data: {boId: self_.boId,boName:self_.boName,boDefId:self_.boDefId}
        };
        Util.open(baseConf, function (action) {
          if (action == "ok") {
            self_.refreshGrid();
          }
        });
      },
      editPrint(record){
        var conf={
          component:this.component,
          title: this.$ti18('rxList.editBtn',"编辑") + this.comment,
          max:true,
          data: {pkId:record.pkId,boDefId:this.boDefId}
        };
        this.handleEdit(conf);
      },
      editOnePrint(){
        var conf={
          component:this.component,
          title: this.$ti18('rxList.editBtn',"编辑") +this.comment,
          max:true
        };
        if(this.selectedRows.length>0){
          conf.data={pkId:this.selectedRows[0].pkId,boDefId:this.boDefId};
          this.handleEdit(conf)
        }
      },
      search(){
        this.$refs.table.loadData()
      },
      close(){
        this.fitSearch = false ;
      }
    }
  }
</script>
<style scoped>

</style>

